package org.docshare.zhuishu;

import java.util.List;
import java.util.zip.Inflater;

import net.tsz.afinal.FinalBitmap;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.tv.TvContentRating;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MyListAdapter extends ArrayAdapter<JSONObject> {



	private static final String TAG = "MyListAdapter";
	private JSONArray objects;
	private FinalBitmap fb;
	int item_layout;
	JSONObject cfg;

	public MyListAdapter(Context context,int item_layout, JSONObject cfg) {
		super(context, item_layout, (List<JSONObject>)cfg.get("data"));;
		this.cfg= cfg;
		this.objects = cfg.getJSONArray("data");
		fb = FinalBitmap.create(context);
		fb.configBitmapLoadThreadSize(5);
		fb.configLoadingImage(R.drawable.loading_0);
		this.item_layout  = item_layout;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Activity activity = (Activity) getContext();
		LayoutInflater inflater = activity.getLayoutInflater();
		
		
		
		if(convertView == null){
			convertView = inflater.inflate(item_layout,null);
		}
		TextView bigt = (TextView) convertView.findViewById(R.id.cfgbigt);
		TextView smallt = (TextView) convertView.findViewById(R.id.cfgsmallt);
		ImageView img = (ImageView) convertView.findViewById(R.id.cfgimg);
		
		JSONObject obj = (JSONObject) objects.get(position);
		if(bigt!=null&& obj.getString("bigt")!=null){
			bigt.setText(obj.getString("bigt"));
		}
		if(smallt!=null && obj.getString("bigt")!=null){
			smallt.setText(obj.getString("smallt"));
		}
		String imgurl = obj.getString("img");
		Log.i(TAG, "imgurl ="+imgurl +"img is "+img);
		if(img!=null && imgurl !=null){
			fb.display(img, imgurl);
		}
		//Bitmap b = BitmapFactory.decodeResource(this.getContext().getResources(), R.drawable.logo);
		//img.setImageBitmap(b);
		
		return convertView;
	}

	
	
	

}
